package com.yanqu.road.entity.musicroom;


import com.yanqu.road.entity.DataObject;
import com.yanqu.road.entity.FieldTypeAnnotation;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

@FieldTypeAnnotation(tableName = "t_u_music_room_beauty", autoSave = true, desc = "妙音坊美女数据")
public class UserMusicRoomBeautyData extends DataObject {

    @FieldTypeAnnotation(desc = "用户Id", select = true, update = true)
    private long userId;

    @FieldTypeAnnotation(desc = "美女id", update = true)
    private int beautyId;

    @FieldTypeAnnotation(desc = "等级")
    private int level;

    @FieldTypeAnnotation(desc = "经验")
    private long exp;

    @FieldTypeAnnotation(desc = "当前舒适度")
    private long comfort;

    @FieldTypeAnnotation(desc = "当前心情值")
    private long mood;

    @FieldTypeAnnotation(desc = "当前饱食度")
    private long satiety;

    @FieldTypeAnnotation(desc = "总舒适度")
    private long totalComfort;

    @FieldTypeAnnotation(desc = "总心情值")
    private long totalMood;

    @FieldTypeAnnotation(desc = "总饱食度")
    private long totalSatiety;

    @FieldTypeAnnotation(desc = "舞蹈")
    private long attr1;

    @FieldTypeAnnotation(desc = "创作")
    private long attr2;

    @FieldTypeAnnotation(desc = "仪态")
    private long attr3;

    @FieldTypeAnnotation(desc = "乐器")
    private long attr4;

    @FieldTypeAnnotation(desc = "声乐")
    private long attr5;

    @FieldTypeAnnotation(desc = "当前皮肤")
    private int nowSkin;

    @FieldTypeAnnotation(desc = "已解锁皮肤")
    private List<Integer> unlockSkins = new ArrayList<>();

    @FieldTypeAnnotation(desc = "入住时间")
    private long liveInTime;
    @FieldTypeAnnotation(desc = "入住的宿舍id")
    private int liveInBuildId;

    @FieldTypeAnnotation(desc = "最近一次结算时辰结束时间")
    private long lastTimerEndTime;
    @FieldTypeAnnotation(desc = "行程列表类型0生活行程,非0工作行程")
    private int scheduleListType;
    @FieldTypeAnnotation(desc = "分配的行程")
    private List<Integer> scheduleList = new ArrayList<>();
    @FieldTypeAnnotation
    private long modifyTime;

    @FieldTypeAnnotation(desc = "当前行程的建筑id")
    private int nowBuildingId;
    @FieldTypeAnnotation(desc = "下一个行程的建筑id")
    private int nextBuildingId;

    public UserMusicRoomBeautyData() {
    }

    public UserMusicRoomBeautyData(long userId, int beautyId) {
        this.userId = userId;
        this.beautyId = beautyId;
        this.level = 1;
        setInsertOption();
    }

    public long getUserId() {
        return userId;
    }

    public void setUserId(long userId) {
        this.userId = userId;
    }

    public int getBeautyId() {
        return beautyId;
    }

    public void setBeautyId(int beautyId) {
        this.beautyId = beautyId;
    }

    public int getLevel() {
        return level;
    }

    public void setLevel(int level) {
        this.level = level;
        setUpdateOption();
    }

    public long getExp() {
        return exp;
    }

    public void setExp(long exp) {
        this.exp = exp;
        setUpdateOption();
    }

    public long getComfort() {
        return comfort;
    }

    public void setComfort(long comfort) {
        this.comfort = comfort;
        setUpdateOption();
    }

    public long getMood() {
        return mood;
    }

    public void setMood(long mood) {
        this.mood = mood;
        setUpdateOption();
    }

    public long getSatiety() {
        return satiety;
    }

    public void setSatiety(long satiety) {
        this.satiety = satiety;
        setUpdateOption();
    }

    public long getTotalComfort() {
        return totalComfort;
    }

    public void setTotalComfort(long totalComfort) {
        this.totalComfort = totalComfort;
        setUpdateOption();
    }

    public long getTotalMood() {
        return totalMood;
    }

    public void setTotalMood(long totalMood) {
        this.totalMood = totalMood;
        setUpdateOption();
    }

    public long getTotalSatiety() {
        return totalSatiety;
    }

    public void setTotalSatiety(long totalSatiety) {
        this.totalSatiety = totalSatiety;
        setUpdateOption();
    }

    public long getAttr1() {
        return attr1;
    }

    public void setAttr1(long attr1) {
        this.attr1 = attr1;
        setUpdateOption();
    }

    public long getAttr2() {
        return attr2;
    }

    public void setAttr2(long attr2) {
        this.attr2 = attr2;
        setUpdateOption();
    }

    public long getAttr3() {
        return attr3;
    }

    public void setAttr3(long attr3) {
        this.attr3 = attr3;
        setUpdateOption();
    }

    public long getAttr4() {
        return attr4;
    }

    public void setAttr4(long attr4) {
        this.attr4 = attr4;
        setUpdateOption();
    }

    public long getAttr5() {
        return attr5;
    }

    public void setAttr5(long attr5) {
        this.attr5 = attr5;
        setUpdateOption();
    }

    public int getNowSkin() {
        return nowSkin;
    }

    public void setNowSkin(int nowSkin) {
        this.nowSkin = nowSkin;
        setUpdateOption();
    }

    public List<Integer> getUnlockSkins() {
        return unlockSkins;
    }

    public void setUnlockSkins(List<Integer> unlockSkins) {
        this.unlockSkins = unlockSkins;
        setUpdateOption();
    }

    public long getModifyTime() {
        return modifyTime;
    }

    public void setModifyTime(long modifyTime) {
        this.modifyTime = modifyTime;
        setUpdateOption();
    }

    public long getLiveInTime() {
        return liveInTime;
    }

    public void setLiveInTime(long liveInTime) {
        this.liveInTime = liveInTime;
        setUpdateOption();
    }

    public int getLiveInBuildId() {
        return liveInBuildId;
    }

    public void setLiveInBuildId(int liveInBuildId) {
        this.liveInBuildId = liveInBuildId;
        setUpdateOption();
    }

    public long getLastTimerEndTime() {
        return lastTimerEndTime;
    }

    public void setLastTimerEndTime(long lastTimerEndTime) {
        this.lastTimerEndTime = lastTimerEndTime;
        setUpdateOption();
    }

    public List<Integer> getScheduleList() {
        return scheduleList;
    }

    public int getSchedule(int timeNumber) {
        if (scheduleList.isEmpty()) {
            return 0;
        }
        int index = timeNumber % scheduleList.size();
        if (index > 0) {
            index--;
        } else if (index == 0){
            index = scheduleList.size() - 1;
        }
        return scheduleList.get(index);
    }

    public void setScheduleList(List<Integer> scheduleList) {
        this.scheduleList = scheduleList;
        setUpdateOption();
    }

    public int getScheduleListType() {
        return scheduleListType;
    }

    public void setScheduleListType(int scheduleListType) {
        this.scheduleListType = scheduleListType;
        setUpdateOption();
    }

    public int getNowBuildingId() {
        return nowBuildingId;
    }

    public void setNowBuildingId(int nowBuildingId) {
        this.nowBuildingId = nowBuildingId;
        setUpdateOption();
    }


    public int getNextBuildingId() {
        return nextBuildingId;
    }

    public void setNextBuildingId(int nextBuildingId) {
        this.nextBuildingId = nextBuildingId;
        setUpdateOption();
    }

    public void setAttr(int index, long newAttrValue) {
        if (index == 0) {
            setAttr1(newAttrValue);
        } else if (index == 1) {
            setAttr2(newAttrValue);
        } else if (index == 2) {
            setAttr3(newAttrValue);
        } else if (index == 3) {
            setAttr4(newAttrValue);
        } else if (index == 4) {
            setAttr5(newAttrValue);
        }
        //改成没有上限从0开始
//        else if (index == 5) {
//            //上限值加了多少,当前值加多少
//            long oldValue = getTotalComfort();
//            setTotalComfort(newAttrValue);
//            setComfort(getComfort() + newAttrValue - oldValue);
//        } else if (index == 6) {
//            long oldValue = getTotalMood();
//            setTotalMood(newAttrValue);
//            setMood(getMood() + newAttrValue - oldValue);
//        } else if (index == 7) {
//            long oldValue = getTotalSatiety();
//            setTotalSatiety(newAttrValue);
//            setSatiety(getSatiety() + newAttrValue - oldValue);
//        }
    }

    public int getRemainComfortPercent() {
        int percent = BigDecimal.valueOf(getComfort() * 1000).divide(BigDecimal.valueOf(getTotalComfort()), 8, BigDecimal.ROUND_UP).setScale(0, BigDecimal.ROUND_HALF_UP).intValue();
        return percent;
    }

    public int getRemainMoodPercent() {
        int percent = BigDecimal.valueOf(getMood() * 1000).divide(BigDecimal.valueOf(getTotalMood()), 8, BigDecimal.ROUND_UP).setScale(0, BigDecimal.ROUND_HALF_UP).intValue();
        return percent;
    }

    public int getRemainSatietyPercent() {
        int percent = BigDecimal.valueOf(getSatiety() * 1000).divide(BigDecimal.valueOf(getTotalSatiety()), 8, BigDecimal.ROUND_UP).setScale(0, BigDecimal.ROUND_HALF_UP).intValue();
        return percent;
    }

    public boolean isAnyOneAttrPercentLessThan(int checkPercent) {
        if (getRemainComfortPercent() < checkPercent)
            return true;
        if (getRemainMoodPercent() < checkPercent)
            return true;
        if (getRemainSatietyPercent() < checkPercent)
            return true;
        return false;
    }

    public boolean isAllAttrPercentMoreThen(int checkPercent) {
        if (getRemainComfortPercent() < checkPercent)
            return false;
        if (getRemainMoodPercent() < checkPercent)
            return false;
        if (getRemainSatietyPercent() < checkPercent)
            return false;
        return true;
    }

    public void resetRouting() {
        setLiveInTime(0);
        setLiveInBuildId(0);
        setLastTimerEndTime(0);
        setNowBuildingId(0);
        setNextBuildingId(0);
        setScheduleListType(0);
        setScheduleList(new ArrayList<Integer>());

        setComfort(0);
        setMood(0);
        setSatiety(0);
    }

    //把属性拼接成字符串
    public String getAttrPrintfStr() {
        StringBuilder sb = new StringBuilder();
        sb.append(getAttr1()).append(",").append(getAttr2()).append(",").append(getAttr3()).append(",").append(getAttr4()).append(",").append(getAttr5());
        return sb.toString();
    }
    public List<Long> getRankAttrList(){
        List<Long> attrList = new ArrayList<>();
        attrList.add(getAttr1());
        attrList.add(getAttr2());
        attrList.add(getAttr3());
        attrList.add(getAttr4());
        attrList.add(getAttr5());
        return attrList;
    }

}
